home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / Multi-Panel Dialogs 1.1 / MPDTest App / App Sources / UTestPrefsDialogHandler.cp < prev    next >
Encoding:
Text File  |  1996-11-09  |  4.4 KB  |  130 lines  |  [TEXT/R*ch]

  1. #include "UTestPrefsDialogHandler.h"
  2.  
  3. #include <LArray.h>
  4. #include <LArrayIterator.h>
  5. #include <LWindow.h>
  6. #include <PP_Messages.h>
  7.  
  8. // This one tells the dialog which pane we need to come back in on.
  9. Int16    StTestPrefsDialogHandler::sLastPanelIndex = 1;
  10. LArray StTestPrefsDialogHandler::sPanelDataHandles(sizeof(Handle));
  11.  
  12. //---------------------------------------------------------------------------
  13. // StTestPrefsDialogHandler::StTestPrefsDialogHandler
  14. //---------------------------------------------------------------------------
  15. //    Constructor
  16. StTestPrefsDialogHandler::StTestPrefsDialogHandler(ResIDT inDialogResID, LCommander *inSuper,
  17.                                                 Int16 inLastPaneIndex, ResIDT inMPDResID)
  18.         : StMPDialogHandler(inDialogResID, inSuper, inLastPaneIndex, inMPDResID)
  19. {
  20.     if ( sPanelDataHandles.GetCount() != (**(MPDHandle)mMPDData).numItems )
  21.     {
  22.         Handle    panelData = nil;
  23.         sPanelDataHandles.InsertItemsAt((**(MPDHandle)mMPDData).numItems, LArray::index_First, &panelData);
  24.     }
  25. }
  26.  
  27. //---------------------------------------------------------------------------
  28. // StTestPrefsDialogHandler::~StTestPrefsDialogHandler
  29. //---------------------------------------------------------------------------
  30. //    Destructor
  31. StTestPrefsDialogHandler::~StTestPrefsDialogHandler()
  32. {
  33. }
  34.  
  35. //---------------------------------------------------------------------------
  36. // StTestPrefsDialogHandler::HandleOK
  37. //---------------------------------------------------------------------------
  38. void StTestPrefsDialogHandler::HandleOK(void)
  39. {
  40.     StMPDialogHandler::HandleOK();
  41.     
  42.     // we want to remember the last panel visited so we can get to it next time 
  43.     // as the initial panel. This is per HIG.
  44.     sLastPanelIndex = GetCurrentPanelIndex();
  45.     
  46.     // This just fakes out the app into believing the preferences were really changed.
  47.     // of course for a real app you'd probably set them in a preferences file.
  48.     for ( short i = 1; i <= (**(MPDHandle)mMPDData).numItems; i++ )
  49.     {
  50.         Handle    newPanelData = RetrievePanelData(i);
  51.         if ( newPanelData != nil )
  52.         {
  53.             Handle temp;
  54.             sPanelDataHandles.FetchItemAt(i, &temp);
  55.             if ( temp != nil )
  56.                 ::DisposeHandle(temp);
  57.                 
  58.             OSErr    anErr = ::HandToHand(&newPanelData);
  59.             ThrowIfOSErr_(anErr);
  60.  
  61.             sPanelDataHandles.AssignItemsAt(1, i, &newPanelData);
  62.         }
  63.     }
  64. }
  65.  
  66. //---------------------------------------------------------------------------
  67. // StTestPrefsDialogHandler::GetPanelData
  68. //---------------------------------------------------------------------------
  69. // This particular implementation uses handles it stores in the object itself. 
  70. // We have an array of handles which correspond 1 to 1 to the panes in the 
  71. // dialog. This way it's quite easy to grab the one we want. But this 
  72. // method you have to overide allows you to do it anyway you wish.
  73. Handle StTestPrefsDialogHandler::GetInitialPanelData(Int16 inPanelIndex)
  74. {
  75.     Handle temp;
  76.     sPanelDataHandles.FetchItemAt(inPanelIndex, &temp);
  77.     if ( temp == nil )
  78.     {
  79.         temp = GetResource('PREF', 1000 + inPanelIndex - 1);
  80.         ThrowIfResFail_(temp);
  81.         ::DetachResource(temp);
  82.         ThrowIfResError_();
  83.     }
  84.     else
  85.     {
  86.         OSErr    anErr = ::HandToHand(&temp);
  87.         ThrowIfOSErr_(anErr);
  88.     }
  89.     return temp;
  90. }
  91.  
  92. //---------------------------------------------------------------------------
  93. // StTestPrefsDialogHandler::GetPanelDefaultData
  94. //---------------------------------------------------------------------------
  95. // This particular implementation uses handles it stores in the object itself. 
  96. // We have an array of handles which correspond 1 to 1 to the panes in the 
  97. // dialog. This way it's quite easy to grab the one we want. But this 
  98. // method you have to overide allows you to do it anyway you wish.
  99. Handle StTestPrefsDialogHandler::GetPanelDefaultData(Int16 inPanelIndex)
  100. {
  101.     Handle temp = GetResource('DFLT', 1000 + inPanelIndex - 1);
  102.     ThrowIfResFail_(temp);
  103.     ::DetachResource(temp);
  104.     ThrowIfResError_();
  105.     return temp;
  106. }
  107.  
  108. //---------------------------------------------------------------------------
  109. // GetPreferences
  110. //---------------------------------------------------------------------------
  111. //    Present a Multi-pane dialog for setting the test application's preferences
  112. //
  113. void StTestPrefsDialogHandler::GetPreferences(LCommander    *inSuper, CommandT inCommand)
  114. {
  115.     StTestPrefsDialogHandler    theHandler(inCommand, inSuper, sLastPanelIndex, inCommand);
  116.  
  117.     // Finish the setup of the dialog panels.
  118.     theHandler.FinishCreate();
  119.     
  120.     theHandler.GetDialog()->Show();
  121.     
  122.     MessageT    hitMessage = -1;
  123.     while ( hitMessage != msg_Cancel && hitMessage != msg_OK ) 
  124.     {
  125.         hitMessage = theHandler.DoDialog();
  126.     }
  127. }
  128.  
  129.  
  130.